package org.marketlive.entity.account;

/*
(C) Copyright MarketLive. 2006. All rights reserved.
MarketLive is a trademark of MarketLive, Inc.
Warning: This computer program is protected by copyright law and international treaties.
Unauthorized reproduction or distribution of this program, or any portion of it, may result
in severe civil and criminal penalties, and will be prosecuted to the maximum extent
possible under the law.
*/

import org.marketlive.entity.IEntityHome;
import org.marketlive.system.encryption.DecryptionException;
import org.marketlive.system.encryption.EncryptionException;

import java.util.Collection;
import java.util.List;

/**
 * Interface to the Customer entity Home object, which provides creation and finder methods for <code>Customer</code>
 * entities.
 */
public interface ICustomerHome extends IEntityHome {

    /**
     * Returns the {@link ICustomer} with the given code. Code must be unique across all customers in the instance.
     * An <code>IllegalArgumentException</code> will be thrown if more than one customer with the given code
     * have been found.
     *
     * @param code the customer code to search on.
     * @return an instance of <code>ICustomer</code> if one is found for the given code, null otherwise.
     */
    ICustomer findByCode(final String code);

    /**
     * Marks a <code>Customer</code> as deleted (delete_flag = true).
     *
     * @param customer to mark as deleted.
     * @deprecated as of MarketLive 5.5 without replacement. Will be removed in the next major release since
     * soft delete will not be supported.
     */
    void markDeleted(final ICustomer customer);

    /**
     * Encrypt the customer's password using the injected decryption class and return an encrypted password String.
     *
     * @param customer entity whose password will be encrypted
     * @return String which represents the encrypted password
     * @throws EncryptionException thrown if the input customer's password, can not be encrypted
     */
    String encryptPassword(ICustomer customer) throws EncryptionException;

    /**
     * Encrypt the customer's password using the injected decryption class and return an encrypted password String.
     *
     * @param password String to be encrypted
     * @return String which represents the encrypted password
     */
    String encryptPassword(String password) throws EncryptionException;

    /**
     * Returns the current key code used to encrypt the customer's password.
     *
     * @return String used to encrypt
     */
    String getEncryptionKeyCode();

    /**
     * Compares two encrypted passwords to see if they match.
     *
     * @param encryptedPassword1 first encrypted password to compare
     * @param encryptedPassword2 second encrypted password to compare
     * @return returns true if they are equal, else false
     */
    boolean comparePasswords(String encryptedPassword1, String encryptedPassword2) throws DecryptionException;

    /**
     * Finds all <code>Customer</code> entities matching the input user name.
     *
     * @param userName to use in matching a customer
     * @return Collection of matching <code>Customer</code> entities
     */
    Collection findByUserName(final IAccountSet accountSet, final String userName);

    /**
     * Finds all <code>Customer</code> entities matching the input email address.
     *
     * @param email to match upon
     * @return Collection of mathcing <code>Customer</code> entities
     */
    Collection findByEmail(final IAccountSet accountSet, final String email);

    /**
     * Creates a <code>Customer</code> entity using the input email address, user name, and password.
     *
     * @param email String value
     * @param userName String value
     * @param password String value
     * @return ICustomer created from the input parameters
     */
    ICustomer create(final IAccountSet accountSet, final String email, final String userName, final String password);
}
